package com.hjm.project.forceReplace.forceReplace.controller;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import com.hjm.common.exception.BusinessException;
import com.hjm.common.utils.LogUtils;
import com.hjm.project.recruitTeam.recruitTeam.domain.RecruitTeam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.forceReplace.forceReplace.domain.ForceReplace;
import com.hjm.project.forceReplace.forceReplace.service.IForceReplaceService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 更新操作Controller
 * 
 * @author LOVE
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/forceReplace/forceReplace")
public class ForceReplaceController extends BaseController
{
    private String prefix = "forceReplace/forceReplace";

    @Autowired
    private IForceReplaceService forceReplaceService;

    @RequiresPermissions("forceReplace:forceReplace:view")
    @GetMapping()
    public String forceReplace()
    {
        return prefix + "/forceReplace";
    }

    /**
     * 查询更新操作列表
     */
    @RequiresPermissions("forceReplace:forceReplace:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ForceReplace forceReplace)
    {
        startPage();
        List<ForceReplace> list = forceReplaceService.selectForceReplaceList(forceReplace);
        return getDataTable(list);
    }

    /**
     * 导出更新操作列表
     */
    @RequiresPermissions("forceReplace:forceReplace:export")
    @Log(title = "更新操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ForceReplace forceReplace)
    {
        List<ForceReplace> list = forceReplaceService.selectForceReplaceList(forceReplace);
        ExcelUtil<ForceReplace> util = new ExcelUtil<ForceReplace>(ForceReplace.class);
        return util.exportExcel(list, "forceReplace");
    }

    /**
     * 新增更新操作
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存更新操作
     */
    @RequiresPermissions("forceReplace:forceReplace:add")
    @Log(title = "更新操作", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ForceReplace forceReplace)
    {
        return toAjax(forceReplaceService.insertForceReplace(forceReplace));
    }

    /**
     * 修改更新操作
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        ForceReplace forceReplace = forceReplaceService.selectForceReplaceById(Long.valueOf(id));
        mmap.put("forceReplace", forceReplace);
        return prefix + "/edit";
    }
    /**
     * 修改更新操作
     */
    @GetMapping("/updatePack")
    public String updatePack(Integer id, ModelMap mmap) {
        ForceReplace forceReplace = forceReplaceService.selectForceReplaceById(Long.valueOf(id));
        mmap.put("forceReplace", forceReplace);
        return prefix + "/updatePack";
    }

    /**
     * 修改保存更新操作
     */
    @RequiresPermissions("forceReplace:forceReplace:edit")
    @Log(title = "更新操作", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ForceReplace forceReplace)
    {
        return toAjax(forceReplaceService.updateForceReplace(forceReplace));
    }

    @Log(title = "更新安装包", businessType = BusinessType.UPDATE)
    @PostMapping("/saveApkPackage")
    @ResponseBody
    public AjaxResult updateApkPackage(@RequestParam("apkFile") MultipartFile apkFile, ForceReplace forceReplace)throws Exception {
        AjaxResult ajaxResult = forceReplaceService.saveApkPackage(apkFile, forceReplace);
        return ajaxResult;
    }

    /**
     * 删除更新操作
     */
    @RequiresPermissions("forceReplace:forceReplace:remove")
    @Log(title = "更新操作", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(forceReplaceService.deleteForceReplaceByIds(ids));
    }
}
